package com.example.Base;



import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.Toast;
import com.example.Fragment.DoctorFragment;
import com.example.Fragment.FindFragment;
import com.example.Fragment.PersonalFragment;
import com.example.Fragment.TrackFragment;
import com.example.administrator.olddoctor.MainActivity;
import com.example.tools.MyProgressBar;

import net.tsz.afinal.FinalHttp;


/**
 * Created by Administrator on 2016/9/26.
 */
public class BaseFragment extends Fragment {
    protected MyProgressBar mPbar;
    protected FinalHttp mFinalHttp;
    private static Toast mToast = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPbar = new MyProgressBar(MainActivity.allThis);
        mFinalHttp = new FinalHttp();
        mFinalHttp.configTimeout(30000);
    }

    public static BaseFragment newInstance(Context context, String tag) {
        BaseFragment baseFragment = null;
        if (tag.equals("1")) {
            baseFragment = new DoctorFragment();
        } else if (tag.equals("2")) {
            baseFragment = new FindFragment();
        } else if (tag.equals("3")) {
            baseFragment = new TrackFragment();
        } else if (tag.equals("4")) {
            baseFragment = new PersonalFragment();
        }
        return baseFragment;
    }

    /**
     * 显示toast
     */
    protected void showToast(String text) {
        if (mToast == null) {
            mToast = Toast.makeText(MainActivity.allThis, text, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(text);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    public static void fragmentgoActivity(Context context, Class clazz, Bundle data) {

        if (context == null) {
            return;
        }
        Intent intent = new Intent(context, clazz);
        if (data != null) {
            intent.putExtras(data);
        }
        context.startActivity(intent);

    }
}
